/*********************************************************************
	\file :           os_sw_layers\bios\mcu\Mcu_Cfg.h
	\brief:           This package contains the user configurations, provided to the user to configure the clock source to the entire system.
	\author:          Manuel Sandoval
	\version:         1.0
	\date:            Sat, 01, March 2014
*********************************************************************/

#ifndef Mcu_Cfg_H
#define Mcu_Cfg_H

/******************************* Includes**********************************/



/******************************* Defines **********************************/


#define CNF_DESIRED_FREQ (48u)			/*!< Frequency desired by the client. */

#define CNF_PLL_AS_CLOCK_SOURCE			/*!< Configures the PLL output as clock signal to the CPU peripherals. */

// #define CFG_XTAL_AS_CLOCK_SOURCE		/*!< Configures the XTAL as clock signal to the CPU peripherals. */

#ifdef CNF_PLL_AS_CLOCK_SOURCE				/*!< It is necessary that PLL is configured as clock source. */
  #define CNF_PLL_AT_MEGAHERTZ_VALUE (4u)	/*!< Configures the PLL to work with 4Mhz XTAL as input. */
#endif

/*!< Value for SYNR s12x MCU configuration register. */
#define CNF_SYNDIV_VALUE     (((CNF_DESIRED_FREQ) / (CNF_FREQ_OSC)) - 1)

/*!< Value for REFDIV s12x MCU configuration register. */
#define CNF_REFDIV_VALUE     ((CNF_FREQ_OSC * (CNF_SYNDIV_VALUE + 1)/ CNF_DESIRED_FREQ) - 1)

/*!< Value for POSTDIV s12x MCU configuration register. */
#define CNF_POSTDIV_VALUE    ((CNF_FVCO / CNF_DESIRED_FREQ) - 1)

/*!< Reference clock frequency selection. */
#define CNF_FREF_VALUE      ((CNF_FREQ_OSC)/(CNF_REFDIV_VALUE + 1))

/*!< Frequency calculated from Fvco, SYNDIV, and REFDIV. */
#define CNF_FVCO        (2 * CNF_FREQ_OSC * ( CNF_SYNDIV_VALUE + 1 )) / (CNF_REFDIV_VALUE + 1 )

/*!< Value calculated from Oscillator. */
#define CNF_FREQ_OSC    CNF_PLL_AT_MEGAHERTZ_VALUE


/*!< Bit are used to configure the VCO gain for optimal stability and lock time. */
#if ((CNF_FVCO >= 32) & (CNF_FVCO <= 48))
  #define CNF_VCOFRQ_VALUE    (0)
#elif ((CNF_FVCO > 48) & (CNF_FVCO <= 80)) 
  #define CNF_VCOFRQ_VALUE    (1)
#elif ((CNF_FVCO > 80) & (CNF_FVCO <= 120))
  #define CNF_VCOFRQ_VALUE    (3)
#else
  /** Selected F_REF frequency is out of range */
    #error  "F_REF Frequency is out of Range" 
#endif 


/*!< Bit are used to configure the internal PLL filter for optimal stability and lock time. */
#if ((CNF_FREF_VALUE >= 1) & (CNF_FREF_VALUE <= 2)) 
  #define CNF_REFFRQ_VALUE (0)
#elif ((CNF_FREF_VALUE > 2) & (CNF_FREF_VALUE <= 6)) 
  #define CNF_REFFRQ_VALUE (1)
#elif ((CNF_FREF_VALUE > 6) & (CNF_FREF_VALUE <= 12))
  #define CNF_REFFRQ_VALUE (2)
#else (CNF_FREF_VALUE > 12)
  #define CNF_REFFRQ_VALUE (3)
#endif


/******************************* Enumerations******************************/


/******************************* Structures *******************************/


/******************************* Global Variables **********************************/


/******************************* Functions ********************************/


/** @} *//* End of MCU configuration Group */

#endif /* Mcu_Cfg_H */

/*********************************************************************
	File	: os_sw_layers\bios\mcu\Mcu_Cfg.h 
*********************************************************************/
